package com.hehe.ai.langchain4j.store;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeServerlessIndexConfig;
import io.pinecone.clients.Pinecone;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: hehe
 * @create: 2025-05-15 12:43
 * @Description:
 */
@Configuration
@RequiredArgsConstructor
public class EmbeddingStoreConfig {

    private final EmbeddingModel embeddingModel;

//    @Value("${pinecone.api-key}")
//    private final String apiKey;
    @Bean
    public EmbeddingStore<TextSegment> embeddingStore() {
        // 创建向量存储
        EmbeddingStore<TextSegment> embeddingStore=PineconeEmbeddingStore.builder()
                .apiKey("pcsk_GEjHf_J3UKtSqcAoaYugxJ85aYK3GUAg1ds95DPs8MwSKti9LbskKBvpxweMDhznD38WM")
                .index("hehe-index") // 如果索引不存在，就创建一个新的索引
                .nameSpace("hehe-namespace") // 如果命名空间不存在，就创建一个新的命名空间不
                .createIndex(PineconeServerlessIndexConfig.builder()
                        .cloud("AWS") //指定索引部署在AWS云服务器上
                        .region("us-east-1") //指定索引所在的 AWS 区域为 us-east-1。
                        .dimension(embeddingModel.dimension()) //指定索引的向量维度，该维度与embeddingModel生成的维度要一致
                        .build()
                ).build();
        return embeddingStore;
    }
}
